#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

const int N = 1e3 + 10, M = 2e4 + 10, INF = 0x3f3f3f3f;

int n, p, k;
int h[N], e[M], w[M], ne[M], id;
int dist[N][N];
bool st[N][N];

void add(int a, int b, int c)
{
    id++;
    e[id] = b; w[id] = c; ne[id] = h[a]; h[a] = id;
}

struct node
{
    int d, x, cnt;
    bool operator<(const node& a) const
    {
        return d > a.d;
    }
};

void dijkstra()
{
    memset(dist, 0x3f, sizeof dist);
    priority_queue<node> heap;
    heap.push({0, 1, 0});
    dist[1][0] = 0;

    while(heap.size())
    {
        node t = heap.top(); heap.pop();
        int x = t.x, cnt = t.cnt;
        if(st[x][cnt]) continue;
        st[x][cnt] = true;

        for(int i = h[x]; i; i = ne[i])
        {
            int y = e[i], z = w[i];
            if(cnt < k && dist[x][cnt] < dist[y][cnt + 1])
            {
                dist[y][cnt + 1] = dist[x][cnt];
                heap.push({dist[y][cnt + 1], y, cnt + 1});
            }

            if(max(dist[x][cnt], z) < dist[y][cnt])
            {
                dist[y][cnt] = max(dist[x][cnt], z);
                heap.push({dist[y][cnt], y, cnt});
            }
        }
    }
}

int main()
{
    cin >> n >> p >> k;
    for(int i = 1; i <= p; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        add(a, b, c); add(b, a, c);
    }

    dijkstra();

    int ret = INF;
    for(int i = 0; i <= k; i++)
        ret = min(ret, dist[n][i]);

    if(ret == INF) cout << -1 << endl;
    else cout << ret << endl;

    return 0;
}



